﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace XYZshell.Game.CardGameEngine
{
	public class Invoker : FlowActivity
	{

		public Invoker() : base()
		{
		}

		public override void Start()
		{
			OnStarted( new InvokerEventArgs
			{
				Parameters=Parameters,
				Path=Path,
				Previous=Previous,
				Next=Next,	
			} );
			int edx=Path.LastIndexOf( '.' );
			string obj=Path.Substring( 0, edx );
			string m=Path.Substring( edx + 1 );
			object o=GameContext.Find( obj );
			GameContext.Invoke( o, m, Parameters );
			OnFinished( new InvokerEventArgs
			{
				Parameters = Parameters,
				Path = Path,
				Previous = Previous,
				Next = Next,	
			} );
		}

		public string Path
		{
			get;
			set;
		}
		public object[] Parameters
		{
			get
			{
				List<object> rtn=new List<object>();
				foreach (ExpressionParam p in Params)
				{
					rtn.Add( p.Value );
				}
				return rtn.ToArray();
			}
		}
		public ExpressionParam[] Params
		{
			get;
			set;
		}

	}
	public class InvokerEventArgs : FlowEventArgs
	{
		public string Path
		{
			get;
			set;
		}
		public object[] Parameters
		{
			get;
			set;
		}

	}
}
